<!--
 * @Author: Zhouxin 2201_75539691@noreply.gitcode.com
 * @Date: 2024-11-20 20:33:50
 * @LastEditors: Zhouxin 2201_75539691@noreply.gitcode.com
 * @LastEditTime: 2024-11-20 22:45:42
 * @FilePath: \2024.11.20-day08-数组与字符串\demo2.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 求一组数中的最大值和最小值，以及所在位置 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [7, 6, 3, 2, 4, 9, 1, 8, 5, 10];
        var max = arr[0];
        var min = arr[0];
        var maxIndex,minIndex;
        for (var i = 1; i < arr.length; i++) {
            if (arr[i] < min) {
                min = arr[i];
                minIndex = i;
            }
            if (arr[i] > max) {
                max = arr[i];
                maxIndex = i;
            }
        }

        console.log("最大值为：" + max+"，下标为："+maxIndex);
        console.log("最小值为：" + min+"，下标为："+minIndex);

    </script>
</body>

</html>